
//由于common.js中存在ajax, 
// 所以在其他页面上common.js必须放在jquery.js下方,此顺序不可改.

{/* <script src="js/jquery.min.js"></script>
<script src="js/common.js"></script> */}

//从本地存储中拿到token并把它放到header中.
$(document).ajaxSend(function(e,xhr,opt) {
    //从本地存储中拿到token
    var token = localStorage.getItem("user_token");
    //把token放到header中
    xhr.setRequestHeader("user_token_header",token);
});
//由于上述代码只对本页面生效,为了让它能对所有页面生效得把上述代码放到common中.

function getUserInfo(url) {
    $.ajax({
        type: "get",
        url: url,
        success:function(result) {
            if(result.code == "SUCCESS" && result.data != null) {
                var userInfo = result.data;
                $(".left .card h3").text(userInfo.userName);
                $(".left .card a").attr("href",userInfo.githubUrl);
            }else {
                alert(result.errMsg);
            }
        },
        error:function(error) {
            console.log(error);
            if(error != null && error.data != null) {
                location.href = "blog_login.html";
            }
        }
    });
}

function logout() {
    localStorage.removeItem("user_token");
    location.href="blog_login.html";
}